package com.woniu.common.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class ResponseData<T> {
    private Integer code;
    private String msg;
    private T data;

    /**
     * @return 成功所返回的值
     */
    public ResponseData success() {
        return new ResponseData(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMsg(), null);
    }

    public ResponseData success(T data) {
        return new ResponseData(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMsg(), data);
    }


    /**
     * @return 失败所返回的值
     */
    public ResponseData fail(ResponseEnum responseEnum) {
        return new ResponseData(responseEnum.getCode(), responseEnum.getMsg(), null);
    }
    public ResponseData fail(ResponseEnum responseEnum,T data) {
        return new ResponseData(responseEnum.getCode(), responseEnum.getMsg(), data);
    }
    public ResponseData fail(){
        return new ResponseData(ResponseEnum.FAIL.getCode(), ResponseEnum.FAIL.getMsg(), null);
    }
}
